$(function(){
    var shopId = 0;
    var areaId = 0;
    // 调用京东等店铺模板
    $.ajax({
        url:'http://193.112.55.79:9090/api/getgsshop',
        dataType:'json',
        success:function(res){
            console.log(res);
            var html = template("jingDong",res);
            $(".jd").html(html);
            window.jd = res.result;
        }
    })

    // 封装公用部分
    var public = function (shopId,areaId){
        $.ajax({
            url: 'http://193.112.55.79:9090/api/getgsproduct',
            dataType: 'json',
            data: { "shopid": shopId, "areaid": areaId },
            success: function (res) {
                console.log(res);
                var html = template("tContent", res);
                // console.log(html);
                $(".t-content").html(html);
            }
        })
}
    // 调用华北等地区的模板
    $.ajax({
        url: 'http://193.112.55.79:9090/api/getgsshoparea',
        dataType: 'json',
        success: function (res) {
            // console.log(res.result[0].areaName.split("（")[0]);
            var html = template("huaBei", res);
            $(".hNorth").html(html);
            window.hNorth = res.result;
        }
    })
    public(0,0);
    // 根据店铺的不同获取对应的商品详情
    $(".jd").on("click", "a",function () {
         shopId = $(this).parent().data("id");
        //  console.log(shopId + ":" + areaId)
        public(shopId, areaId);
        $(".jd_bth").html(window.jd[shopId].shopName +'&nbsp;<span class="caret"></span>');
    })

    // 根据区域的不同获取相对应的商品详情
    $(".hNorth").on("click","a", function () {
        areaId = $(this).parent().data("id");
        // console.log(shopId + ":" + areaId)
        public(shopId, areaId);
        $(".north-btn").html(window.hNorth[areaId].areaName.split("（")[0] + '&nbsp;<span class="caret"></span>');
    })
   
})
